//
//  BIZTopicImageCell.m
//  biz
//
//  Created by zhangfuwei on 2017/7/7.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZTopicImageCell.h"
#import "BIZHotTopicParentListModel.h"

@interface BIZTopicImageCell ()
/** 文章入口Label */
@property (nonatomic, strong) UILabel *articleLabel;
/** 隐藏文章片数,必读,专题 */
@property (nonatomic, assign) BOOL hidden;

@end

@implementation BIZTopicImageCell {
    UIImageView *_bgImageV;
    UIImageView *_topicImageV;
    UIImageView *_readImageV;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor zfw_ColorWithHex:0xf9f9f9 alpha:1.0];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initSubViews];
        
    }
    return self;
}

- (void)initSubViews {
    
    _bgImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, Main_Screen_Width, 185)];
    
    _topicImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 11, 59, 25)];
    [_topicImageV setImage:[UIImage imageNamed:@"hotTopic_topic"]];

    _readImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hotTopic_Reading"]];
    
    _readImageV.frame = CGRectMake(Main_Screen_Width-73, 112, 58, 56);
    
    [self.contentView addSubview:_bgImageV];
    [self.contentView addSubview:_topicImageV];
    [self.contentView addSubview:_readImageV];
    [self.contentView addSubview:self.articleLabel];
}


#pragma mark - class method
+ (BIZTopicImageCell *)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath hidden:(BOOL)hidden
{
    BIZTopicImageCell *cell = [tableView dequeueReusableCellWithIdentifier:kTopicImageCellID forIndexPath:indexPath];
    cell.hidden = hidden;
    return cell;
}

#pragma mark -- set方法
-(void)setChannelModel:(BIZHotTopicParentListChannelModel *)channelModel {
    _channelModel = channelModel;
    
    [SDWebImageTool imageView:_bgImageV
                    imageName:channelModel.imgs
                  placeHolder:@"player_banner"
                 showProgress:YES];
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d篇文章 >>",channelModel.issuesCount] attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:CHINESE_SYSTEM(12)}];

    _articleLabel.attributedText = attStr;
    
    _readImageV.hidden = _hidden;
    _articleLabel.hidden = _hidden;
    _topicImageV.hidden = _hidden;

    [self layoutIfNeeded];
}

#pragma mark -- lazyload

- (UILabel *)articleLabel {
    if (!_articleLabel) {
        _articleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 145, 75, 25)];
        _articleLabel.backgroundColor = [UIColor zfw_ColorWithHex:0x000 alpha:0.6];
        _articleLabel.layer.cornerRadius = 13.0f;
        _articleLabel.layer.masksToBounds = YES;
        
        _articleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _articleLabel;
}

@end
